//
//  NextImageViewController.m
//  Travelmemory
//
//  Created by lanou3g on 16/3/24.
//  Copyright © 2016年 ABCD. All rights reserved.
//

#import "NextImageViewController.h"
#import "UMSocialDataService.h"
@interface NextImageViewController ()<UMSocialDataDelegate, UIWebViewDelegate>

@property (nonatomic, strong) UIWebView *webView;
@property (nonatomic , copy) NSString *urlStr;

@end

@implementation NextImageViewController

//  加载webView
- (UIWebView *)webView {
    if (!_webView) {
        self.webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
        // 设置webview自适应
        self.webView.scalesPageToFit = YES;
        self.webView.dataDetectorTypes = UIDataDetectorTypeAll;
        self.webView.scrollView.showsVerticalScrollIndicator = NO;
        self.webView.delegate = self;
        [self.view addSubview:self.webView];
    }
    return _webView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = self.model.name;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"share"] style:UIBarButtonItemStyleDone target:self action:@selector(shareButton)];
    if (self.model.url != nil) {
        self.urlStr = self.model.url;
    }else if (self.model.html_url != nil) {
        self.urlStr = self.model.html_url;
    }else if ([self.model.desc isEqualToString:@"热门游记"]) {
        self.urlStr = [NSString stringWithFormat:@"http://web.breadtrip.com/trips/%@/", self.model.ID];
    }else {
        self.urlStr = [NSString stringWithFormat:@"http://web.breadtrip.com/btrip/spot/%@/?sns_share=101", self.model.spot_id];
    }
    
//    [GiFHUD setGifWithImageName:@"pika.gif"];
//    [GiFHUD show];
    
    NSURL *url = [NSURL URLWithString:self.urlStr];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [self.webView loadRequest:request];
    
    
}

- (void)viewWillAppear:(BOOL)animated{
    
    self.tabBarController.tabBar.hidden = YES;
}

#pragma mark - 分享

- (void)shareButton {
    NSString *shareText = [NSString stringWithFormat:@"开心的旅行由心开始... %@ %@", self.model.text, self.urlStr];
    NSString *shareImage;
    if (self.model.app5_cover_url != nil) {
        shareImage = [NSString stringWithFormat:@"%@", self.model.app5_cover_url];
    }else if (self.model.cover_image != nil) {
        shareImage = self.model.cover_image;
    }
    else {
        shareImage = self.model.image_url;
    }
//    NSLog(@"%@",shareText);
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
